package com.eden.door.entity;  

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.eden.door.constant.Constant_Sys;


public class Formula implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 计算这个功式,传入所有参数,计算好后定入这个列中,返回
	 * @param doorAttrMap
	 * @return
	 */
	public Map<String ,DoorAttr> calculate(Map<String , DoorAttr> doorAttrMap) {
		
		return doorAttrMap ;
	}
	
	/**
	 * 从属性集合中取值
	 * @param code 属性代码
	 * @param doorAttrMap 属性Map
	 * @return 返会String
	 */
	public String getValueByCode(String code , Map<String , DoorAttr> doorAttrMap ) {
		DoorAttr doorAttr = doorAttrMap.get(code);
		if(StringUtils.equals(doorAttr.getType() , Constant_Sys.DOOR_ATTR_TYPE_TEXT))
			return StringUtils.isBlank(doorAttrMap.get(code).getValue()) ? "0" : doorAttrMap.get(code).getValue() ;
		else if(StringUtils.equals(doorAttr.getType() , Constant_Sys.DOOR_ATTR_TYPE_SELECT)){
			List<Option> optList = doorAttr.getOptList() ;
			for(Option o : optList){
				if(StringUtils.equals(doorAttr.getValue(), o.getText())){
					return o.getValue();
				}
			}
		}
		
		return "0" ;
	}
}
